{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Getting Financial Data - Pandas Datareader"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Introduction:\n",
    "\n",
    "This time you will get data from a website.\n",
    "\n",
    "\n",
    "### Step 1. Import the necessary libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# package to extract data from various Internet sources into a DataFrame\n",
    "# make sure you have it installed\n",
    "import pandas_datareader.data as web\n",
    "\n",
    "# package for dates\n",
    "import datetime as dt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 2. Create your time range (start and end variables). The start date should be 01/01/2015 and the end should today (whatever your today is)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2015, 1, 1, 0, 0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 3. Get an API key for one of the APIs that are supported by Pandas Datareader, preferably for AlphaVantage.\n",
    "\n",
    "If you do not have an API key for any of the supported APIs, it is easiest to get one for [AlphaVantage](https://www.alphavantage.co/support/#api-key). (Note that the API key is shown directly after the signup. You do *not* receive it via e-mail.)\n",
    "\n",
    "(For a full list of the APIs that are supported by Pandas Datareader, [see here](https://pydata.github.io/pandas-datareader/readers/index.html). As the APIs are provided by third parties, this list may change.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 4. Use Pandas Datarader to read the daily time series for the Apple stock (ticker symbol AAPL) between 01/01/2015 and today, assign it to df_apple and print it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <td>111.3900</td>\n",
       "      <td>111.4400</td>\n",
       "      <td>107.350</td>\n",
       "      <td>109.33</td>\n",
       "      <td>53204626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>108.2900</td>\n",
       "      <td>108.6500</td>\n",
       "      <td>105.410</td>\n",
       "      <td>106.25</td>\n",
       "      <td>64285491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>106.5400</td>\n",
       "      <td>107.4300</td>\n",
       "      <td>104.630</td>\n",
       "      <td>106.26</td>\n",
       "      <td>65797116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>107.2000</td>\n",
       "      <td>108.2000</td>\n",
       "      <td>106.695</td>\n",
       "      <td>107.75</td>\n",
       "      <td>40105934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>109.2300</td>\n",
       "      <td>112.1500</td>\n",
       "      <td>108.700</td>\n",
       "      <td>111.89</td>\n",
       "      <td>59364547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-24</th>\n",
       "      <td>514.7900</td>\n",
       "      <td>515.1400</td>\n",
       "      <td>495.745</td>\n",
       "      <td>503.43</td>\n",
       "      <td>86484442</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-25</th>\n",
       "      <td>498.7900</td>\n",
       "      <td>500.7172</td>\n",
       "      <td>492.210</td>\n",
       "      <td>499.30</td>\n",
       "      <td>52873947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-26</th>\n",
       "      <td>504.7165</td>\n",
       "      <td>507.9700</td>\n",
       "      <td>500.330</td>\n",
       "      <td>506.09</td>\n",
       "      <td>40755567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-27</th>\n",
       "      <td>508.5700</td>\n",
       "      <td>509.9400</td>\n",
       "      <td>495.330</td>\n",
       "      <td>500.04</td>\n",
       "      <td>38888096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-28</th>\n",
       "      <td>504.0500</td>\n",
       "      <td>505.7700</td>\n",
       "      <td>498.310</td>\n",
       "      <td>499.23</td>\n",
       "      <td>46907479</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1425 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high      low   close    volume\n",
       "2015-01-02  111.3900  111.4400  107.350  109.33  53204626\n",
       "2015-01-05  108.2900  108.6500  105.410  106.25  64285491\n",
       "2015-01-06  106.5400  107.4300  104.630  106.26  65797116\n",
       "2015-01-07  107.2000  108.2000  106.695  107.75  40105934\n",
       "2015-01-08  109.2300  112.1500  108.700  111.89  59364547\n",
       "...              ...       ...      ...     ...       ...\n",
       "2020-08-24  514.7900  515.1400  495.745  503.43  86484442\n",
       "2020-08-25  498.7900  500.7172  492.210  499.30  52873947\n",
       "2020-08-26  504.7165  507.9700  500.330  506.09  40755567\n",
       "2020-08-27  508.5700  509.9400  495.330  500.04  38888096\n",
       "2020-08-28  504.0500  505.7700  498.310  499.23  46907479\n",
       "\n",
       "[1425 rows x 5 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 5. Add a new column \"stock\" to the dataframe and add the ticker symbol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>stock</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <td>111.3900</td>\n",
       "      <td>111.4400</td>\n",
       "      <td>107.350</td>\n",
       "      <td>109.33</td>\n",
       "      <td>53204626</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>108.2900</td>\n",
       "      <td>108.6500</td>\n",
       "      <td>105.410</td>\n",
       "      <td>106.25</td>\n",
       "      <td>64285491</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>106.5400</td>\n",
       "      <td>107.4300</td>\n",
       "      <td>104.630</td>\n",
       "      <td>106.26</td>\n",
       "      <td>65797116</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>107.2000</td>\n",
       "      <td>108.2000</td>\n",
       "      <td>106.695</td>\n",
       "      <td>107.75</td>\n",
       "      <td>40105934</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>109.2300</td>\n",
       "      <td>112.1500</td>\n",
       "      <td>108.700</td>\n",
       "      <td>111.89</td>\n",
       "      <td>59364547</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-24</th>\n",
       "      <td>514.7900</td>\n",
       "      <td>515.1400</td>\n",
       "      <td>495.745</td>\n",
       "      <td>503.43</td>\n",
       "      <td>86484442</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-25</th>\n",
       "      <td>498.7900</td>\n",
       "      <td>500.7172</td>\n",
       "      <td>492.210</td>\n",
       "      <td>499.30</td>\n",
       "      <td>52873947</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-26</th>\n",
       "      <td>504.7165</td>\n",
       "      <td>507.9700</td>\n",
       "      <td>500.330</td>\n",
       "      <td>506.09</td>\n",
       "      <td>40755567</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-27</th>\n",
       "      <td>508.5700</td>\n",
       "      <td>509.9400</td>\n",
       "      <td>495.330</td>\n",
       "      <td>500.04</td>\n",
       "      <td>38888096</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-28</th>\n",
       "      <td>504.0500</td>\n",
       "      <td>505.7700</td>\n",
       "      <td>498.310</td>\n",
       "      <td>499.23</td>\n",
       "      <td>46907479</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1425 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high      low   close    volume stock\n",
       "2015-01-02  111.3900  111.4400  107.350  109.33  53204626  AAPL\n",
       "2015-01-05  108.2900  108.6500  105.410  106.25  64285491  AAPL\n",
       "2015-01-06  106.5400  107.4300  104.630  106.26  65797116  AAPL\n",
       "2015-01-07  107.2000  108.2000  106.695  107.75  40105934  AAPL\n",
       "2015-01-08  109.2300  112.1500  108.700  111.89  59364547  AAPL\n",
       "...              ...       ...      ...     ...       ...   ...\n",
       "2020-08-24  514.7900  515.1400  495.745  503.43  86484442  AAPL\n",
       "2020-08-25  498.7900  500.7172  492.210  499.30  52873947  AAPL\n",
       "2020-08-26  504.7165  507.9700  500.330  506.09  40755567  AAPL\n",
       "2020-08-27  508.5700  509.9400  495.330  500.04  38888096  AAPL\n",
       "2020-08-28  504.0500  505.7700  498.310  499.23  46907479  AAPL\n",
       "\n",
       "[1425 rows x 6 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 6. Repeat the two previous steps for a few other stocks, always creating a new dataframe: Tesla, IBM and Microsoft. (Ticker symbols TSLA, IBM and MSFT.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 7. Combine the four separate dataFrames into one combined dataFrame df that holds the information for all four stocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>stock</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <td>111.39</td>\n",
       "      <td>111.440</td>\n",
       "      <td>107.350</td>\n",
       "      <td>109.33</td>\n",
       "      <td>53204626</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>108.29</td>\n",
       "      <td>108.650</td>\n",
       "      <td>105.410</td>\n",
       "      <td>106.25</td>\n",
       "      <td>64285491</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>106.54</td>\n",
       "      <td>107.430</td>\n",
       "      <td>104.630</td>\n",
       "      <td>106.26</td>\n",
       "      <td>65797116</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>107.20</td>\n",
       "      <td>108.200</td>\n",
       "      <td>106.695</td>\n",
       "      <td>107.75</td>\n",
       "      <td>40105934</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>109.23</td>\n",
       "      <td>112.150</td>\n",
       "      <td>108.700</td>\n",
       "      <td>111.89</td>\n",
       "      <td>59364547</td>\n",
       "      <td>AAPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-24</th>\n",
       "      <td>214.79</td>\n",
       "      <td>215.520</td>\n",
       "      <td>212.430</td>\n",
       "      <td>213.69</td>\n",
       "      <td>25460147</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-25</th>\n",
       "      <td>213.10</td>\n",
       "      <td>216.610</td>\n",
       "      <td>213.100</td>\n",
       "      <td>216.47</td>\n",
       "      <td>23043696</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-26</th>\n",
       "      <td>217.88</td>\n",
       "      <td>222.090</td>\n",
       "      <td>217.360</td>\n",
       "      <td>221.15</td>\n",
       "      <td>39600828</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-27</th>\n",
       "      <td>222.89</td>\n",
       "      <td>231.150</td>\n",
       "      <td>219.400</td>\n",
       "      <td>226.58</td>\n",
       "      <td>57602195</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-28</th>\n",
       "      <td>228.18</td>\n",
       "      <td>230.644</td>\n",
       "      <td>226.580</td>\n",
       "      <td>228.91</td>\n",
       "      <td>26292896</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5700 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              open     high      low   close    volume stock\n",
       "2015-01-02  111.39  111.440  107.350  109.33  53204626  AAPL\n",
       "2015-01-05  108.29  108.650  105.410  106.25  64285491  AAPL\n",
       "2015-01-06  106.54  107.430  104.630  106.26  65797116  AAPL\n",
       "2015-01-07  107.20  108.200  106.695  107.75  40105934  AAPL\n",
       "2015-01-08  109.23  112.150  108.700  111.89  59364547  AAPL\n",
       "...            ...      ...      ...     ...       ...   ...\n",
       "2020-08-24  214.79  215.520  212.430  213.69  25460147  MSFT\n",
       "2020-08-25  213.10  216.610  213.100  216.47  23043696  MSFT\n",
       "2020-08-26  217.88  222.090  217.360  221.15  39600828  MSFT\n",
       "2020-08-27  222.89  231.150  219.400  226.58  57602195  MSFT\n",
       "2020-08-28  228.18  230.644  226.580  228.91  26292896  MSFT\n",
       "\n",
       "[5700 rows x 6 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 8. Shift the stock column into the index (making it a multi-level index consisting of the ticker symbol and the date)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>stock</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>111.39</td>\n",
       "      <td>111.440</td>\n",
       "      <td>107.350</td>\n",
       "      <td>109.33</td>\n",
       "      <td>53204626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>108.29</td>\n",
       "      <td>108.650</td>\n",
       "      <td>105.410</td>\n",
       "      <td>106.25</td>\n",
       "      <td>64285491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>106.54</td>\n",
       "      <td>107.430</td>\n",
       "      <td>104.630</td>\n",
       "      <td>106.26</td>\n",
       "      <td>65797116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>107.20</td>\n",
       "      <td>108.200</td>\n",
       "      <td>106.695</td>\n",
       "      <td>107.75</td>\n",
       "      <td>40105934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>109.23</td>\n",
       "      <td>112.150</td>\n",
       "      <td>108.700</td>\n",
       "      <td>111.89</td>\n",
       "      <td>59364547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-24</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>214.79</td>\n",
       "      <td>215.520</td>\n",
       "      <td>212.430</td>\n",
       "      <td>213.69</td>\n",
       "      <td>25460147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-25</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>213.10</td>\n",
       "      <td>216.610</td>\n",
       "      <td>213.100</td>\n",
       "      <td>216.47</td>\n",
       "      <td>23043696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-26</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>217.88</td>\n",
       "      <td>222.090</td>\n",
       "      <td>217.360</td>\n",
       "      <td>221.15</td>\n",
       "      <td>39600828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-27</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>222.89</td>\n",
       "      <td>231.150</td>\n",
       "      <td>219.400</td>\n",
       "      <td>226.58</td>\n",
       "      <td>57602195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-28</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>228.18</td>\n",
       "      <td>230.644</td>\n",
       "      <td>226.580</td>\n",
       "      <td>228.91</td>\n",
       "      <td>26292896</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5700 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    open     high      low   close    volume\n",
       "           stock                                            \n",
       "2015-01-02 AAPL   111.39  111.440  107.350  109.33  53204626\n",
       "2015-01-05 AAPL   108.29  108.650  105.410  106.25  64285491\n",
       "2015-01-06 AAPL   106.54  107.430  104.630  106.26  65797116\n",
       "2015-01-07 AAPL   107.20  108.200  106.695  107.75  40105934\n",
       "2015-01-08 AAPL   109.23  112.150  108.700  111.89  59364547\n",
       "...                  ...      ...      ...     ...       ...\n",
       "2020-08-24 MSFT   214.79  215.520  212.430  213.69  25460147\n",
       "2020-08-25 MSFT   213.10  216.610  213.100  216.47  23043696\n",
       "2020-08-26 MSFT   217.88  222.090  217.360  221.15  39600828\n",
       "2020-08-27 MSFT   222.89  231.150  219.400  226.58  57602195\n",
       "2020-08-28 MSFT   228.18  230.644  226.580  228.91  26292896\n",
       "\n",
       "[5700 rows x 5 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 7. Create a dataFrame called vol, with the volume values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>stock</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-02</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>53204626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>64285491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>65797116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>40105934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <th>AAPL</th>\n",
       "      <td>59364547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-24</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>25460147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-25</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>23043696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-26</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>39600828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-27</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>57602195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-28</th>\n",
       "      <th>MSFT</th>\n",
       "      <td>26292896</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5700 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    volume\n",
       "           stock          \n",
       "2015-01-02 AAPL   53204626\n",
       "2015-01-05 AAPL   64285491\n",
       "2015-01-06 AAPL   65797116\n",
       "2015-01-07 AAPL   40105934\n",
       "2015-01-08 AAPL   59364547\n",
       "...                    ...\n",
       "2020-08-24 MSFT   25460147\n",
       "2020-08-25 MSFT   23043696\n",
       "2020-08-26 MSFT   39600828\n",
       "2020-08-27 MSFT   57602195\n",
       "2020-08-28 MSFT   26292896\n",
       "\n",
       "[5700 rows x 1 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 8. Aggregate the data of volume to weekly.\n",
    "Hint: Be careful to not sum data from the same week of 2015 and other years."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>stock</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>IBM</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>TSLA</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">2015</th>\n",
       "      <th>1</th>\n",
       "      <td>53204626</td>\n",
       "      <td>5525341</td>\n",
       "      <td>27913852</td>\n",
       "      <td>4764443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>282868187</td>\n",
       "      <td>24440360</td>\n",
       "      <td>158596624</td>\n",
       "      <td>22622034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>304226647</td>\n",
       "      <td>23272056</td>\n",
       "      <td>157088136</td>\n",
       "      <td>30799137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>198737041</td>\n",
       "      <td>31230797</td>\n",
       "      <td>137352632</td>\n",
       "      <td>16215501</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>465842684</td>\n",
       "      <td>32927307</td>\n",
       "      <td>437786778</td>\n",
       "      <td>15720217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">2020</th>\n",
       "      <th>31</th>\n",
       "      <td>211898609</td>\n",
       "      <td>20010578</td>\n",
       "      <td>149372422</td>\n",
       "      <td>61152261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>250852555</td>\n",
       "      <td>17701697</td>\n",
       "      <td>217598950</td>\n",
       "      <td>37091084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>235474473</td>\n",
       "      <td>18634659</td>\n",
       "      <td>141752091</td>\n",
       "      <td>71049854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>208464758</td>\n",
       "      <td>15908978</td>\n",
       "      <td>132258021</td>\n",
       "      <td>90804281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>265909531</td>\n",
       "      <td>16959794</td>\n",
       "      <td>171999762</td>\n",
       "      <td>88736115</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>296 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "stock           AAPL       IBM       MSFT      TSLA\n",
       "year week                                          \n",
       "2015 1      53204626   5525341   27913852   4764443\n",
       "     2     282868187  24440360  158596624  22622034\n",
       "     3     304226647  23272056  157088136  30799137\n",
       "     4     198737041  31230797  137352632  16215501\n",
       "     5     465842684  32927307  437786778  15720217\n",
       "...              ...       ...        ...       ...\n",
       "2020 31    211898609  20010578  149372422  61152261\n",
       "     32    250852555  17701697  217598950  37091084\n",
       "     33    235474473  18634659  141752091  71049854\n",
       "     34    208464758  15908978  132258021  90804281\n",
       "     35    265909531  16959794  171999762  88736115\n",
       "\n",
       "[296 rows x 4 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 9. Find all the volume traded in the year of 2015"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>stock</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>IBM</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>TSLA</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015</th>\n",
       "      <td>13064316775</td>\n",
       "      <td>1105545521</td>\n",
       "      <td>9057582311</td>\n",
       "      <td>1086708380</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "stock         AAPL         IBM        MSFT        TSLA\n",
       "year                                                  \n",
       "2015   13064316775  1105545521  9057582311  1086708380"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
